package com.newlink.building.common_base.ext

import android.content.Intent
import android.os.Bundle
import android.os.Parcelable
import java.io.Serializable

/**
 * @Author: Jake
 * @Date: 2024-04-23
 * @Description:
 */

fun Intent.getInt(name: String): Int {
    return getInt(name, 0)
}

fun Intent.getInt(name: String, defaultValue: Int): Int {
    val bundle: Bundle = extras ?: return defaultValue
    return bundle.getInt(name, defaultValue)
}

fun Intent.getString(name: String): String? {
    val bundle: Bundle = extras ?: return null
    return bundle.getString(name)
}

fun Intent.getString(name: String, defaultValue: String): String {
    val bundle: Bundle = extras ?: return defaultValue
    return bundle.getString(name, defaultValue)
}

fun Intent.getBoolean(name: String): Boolean {
    return getBoolean(name, false)
}

fun Intent.getBoolean(name: String, defaultValue: Boolean): Boolean {
    val bundle: Bundle = extras ?: return defaultValue
    return bundle.getBoolean(name, defaultValue)
}

fun Intent.getStringArrayList(name: String): ArrayList<String?>? {
    val bundle: Bundle = extras ?: return null
    return bundle.getStringArrayList(name)
}

fun <P : Parcelable?> Intent.getParcelable(name: String): P? {
    val bundle: Bundle = extras ?: return null
    return bundle.getParcelable(name)
}

@Suppress("UNCHECKED_CAST")
fun <S : Serializable?> Intent.getSerializable(name: String): S? {
    val bundle: Bundle = extras ?: return null
    return (bundle.getSerializable(name)) as S?
}